package com.wkh.datastructure;
//递归实现二分查找
public class RecursionBinarySearch {
    private static int search(int[] arr, int target, int low, int high){
        if (low>high){
            return -1;
        }
        int m = (low+high)>>>1;
        if (target > arr[low]){
            return search(arr,target,m+1,high);
        }else if (target<arr[m]){
            return search(arr,target,low,m-1);
        }else {
            return m;
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        int index = search(arr, 8, 0, arr.length - 1);
        System.out.println(index);
    }
}
